package com.lsa.letcode.the43.multStr;

import java.math.BigInteger;

import org.junit.Assert;
import org.junit.Test;

public class MultiplyTest {
	@Test
	public void test() {
		Solution s = new Solution();
//		System.out.println(s.multiply("120", 9));
		System.out.println(s.multiply("45", "3"));
		
		testMultByDigit(s, 120, 9);
		testMultByDigit(s, 999, 3);
		testMultByDigit(s, 9, 9);
		testMultByDigit(s, 9, 8);
		testMultByDigit(s, 999, 1);
		
		testAdd(s, 999, 111);
		testAdd(s, 123, 33);
		testAdd(s, 12, 33);
		testAdd(s, 9000, 111);
		testAdd(s, 9, 12);
		
		testMult(s, 12, 12);
		testMult(s, 9, 9);
		testMult(s, 12, 8);
		testMult(s, 8, 12);
		testMult(s, 1, 12);
		testMult(s, 12, 1);
		testMult(s, 12, 0);
		testMult(s, 0, 12);
		
//		System.out.println(Solution.multiplied10(new Solution.CharBuffer("000675"), 3)); 
		

//		System.out.println(new Solution.CharBuffer("0123456789".toCharArray(), 0, 3));
		
		testMult(s, "1234561234561234567890999999999999", "1234561234561234567890999999999999");
		
//		Assert.assertEquals(""+(n1+n2), s.add("" + n1, "" + n2));
//		Assert.assertEquals("132", s.multiply("12", "11"));
	}

	private void testAdd(Solution s, int n1, int n2) {
		Solution.CharBuffer r = new Solution.CharBuffer('0', Math.max(("" + n1).length(), ("" + n2).length()) + 1);
		s.add("" + n1, "" + n2, r);
		Assert.assertEquals(""+(n1+n2), Solution.trimLeadingZeroes(r).toString());
	}
	
	private void testMultByDigit(Solution s, int n1, int n2) {
		Solution.CharBuffer r = new Solution.CharBuffer('0', ("" + n1).length() + 1);
		s.multiply("" + n1, n2, r);
		Assert.assertEquals(""+(n1*n2), Solution.trimLeadingZeroes(r).toString());
	}
	
	private void testMult(Solution s, int n1, int n2) {
		String res = s.multiply("" + n1, ""+n2);
		Assert.assertEquals(""+(n1*n2), res.toString());
	}
	
	private void testMult(Solution s, String n1, String n2) {
		BigInteger bi1 = new BigInteger(n1);
		BigInteger bi2 = new BigInteger(n2);
		
		String res = s.multiply("" + n1, ""+n2);
		Assert.assertEquals(bi1.multiply(bi2).toString(), res.toString());
	}
}
